const install = function (app) {
  app.directive("permission", (el, binding) => {
    const { value } = binding;
    //const userRoles = getCurrentUserRoles() // 获取当前用户角色的方法
    const userRoles = ["admin"]; //模拟数据

    if (value && value instanceof Array && value.length > 0) {
      const hasPermission = userRoles.some((role) => value.includes(role));

      if (!hasPermission) {
        el.parentNode && el.parentNode.removeChild(el);
      }
    } else {
      throw new Error(`需要指定权限，例如 v-permission="['admin','editor']"`);
    }
  });
};

export default install;
